/**
 * @file		dd_pmc_gpio.h
 * @brief		PMC GPIO driver
 * @note		None
 * @attention	None
 * 
 * <B><I>Copyright 2016 Socionext Inc.</I></B>
 */

/** @weakgroup dd_pmc_gpio_overview
@{
	CM0 PMC - GPIO Driver.<br>
@}*//* --- end of dd_pmc_gpio_overview */

#ifndef _DD_PMC_GPIO_H_
#define _DD_PMC_GPIO_H_

/** @weakgroup dd_pmc_gpio_definition
@{*/

#include "driver_common.h"


/*----------------------------------------------------------------------*/
/* Definition															*/
/*----------------------------------------------------------------------*/
/**
// Error Code
*/
#define	D_DD_PMC_GPIO_INPUT_PARAM_ERROR		(D_DD_PMC_GPIO | D_DDIM_INPUT_PARAM_ERROR)	/**< Input parameter error. */
#define	D_DD_PMC_GPIO_STATUS_ABNORMAL		(D_DD_PMC_GPIO | D_DDIM_STATUS_ABNORMAL) 	/**< Abnormal status error. */

// GPIO
// GPIO functional type (EPCR)
#define D_DD_PMC_GPIO_GPIO_FUNC_GPIO	(0)		/**< GPIO mode */
#define D_DD_PMC_GPIO_GPIO_FUNC_HWMODE	(1)		/**< Hardware mode (Resource output signal) */

// GPIO direction (DDR)
#define D_DD_PMC_GPIO_GPIO_DIR_IN		(0)		/**< Input port */
#define D_DD_PMC_GPIO_GPIO_DIR_OUT		(1)		/**< Output port */

// GPIO status (PDR)
#define D_DD_PMC_GPIO_GPIO_STATUS_LOW	(0)		/**< Low status */
#define D_DD_PMC_GPIO_GPIO_STATUS_HIGH	(1)		/**< High status */

// GPIO pull-up/down register enable (PUDER)
#define D_DD_PMC_GPIO_GPIO_PUD_OFF		(0)		/**< Pull-up/down disable */
#define D_DD_PMC_GPIO_GPIO_PUD_ON		(1)		/**< Pull-up/down enable */

// GPIO pull-up/down register control (PUDCR)
#define D_DD_PMC_GPIO_GPIO_PUD_DOWN		(0)		/**< Pull-down */
#define D_DD_PMC_GPIO_GPIO_PUD_UP		(1)		/**< Pull-Up */



/*----------------------------------------------------------------------*/
/* Enumeration															*/
/*----------------------------------------------------------------------*/
/** GPIO port name */
typedef enum {
	E_DD_PMC_GPIO_P00	= 0,		/**< GPIO port P00 */
	E_DD_PMC_GPIO_P01,				/**< GPIO port P01 */
	E_DD_PMC_GPIO_P02,				/**< GPIO port P02 */
	E_DD_PMC_GPIO_P03,				/**< GPIO port P03 */
	E_DD_PMC_GPIO_P04,				/**< GPIO port P04 */
	E_DD_PMC_GPIO_P05,				/**< GPIO port P05 */
	E_DD_PMC_GPIO_P06,				/**< GPIO port P06 */
	E_DD_PMC_GPIO_P07,				/**< GPIO port P07 */
	E_DD_PMC_GPIO_P10,				/**< GPIO port P10 */
	E_DD_PMC_GPIO_P11,				/**< GPIO port P11 */
	E_DD_PMC_GPIO_P12,				/**< GPIO port P12 */
	E_DD_PMC_GPIO_P13,				/**< GPIO port P13 */
	E_DD_PMC_GPIO_P14,				/**< GPIO port P14 */
	E_DD_PMC_GPIO_P15,				/**< GPIO port P15 */
	E_DD_PMC_GPIO_P16,				/**< GPIO port P16 */
	E_DD_PMC_GPIO_P17,				/**< GPIO port P17 */
	E_DD_PMC_GPIO_P20,				/**< GPIO port P20 */
	E_DD_PMC_GPIO_P21,				/**< GPIO port P21 */
	E_DD_PMC_GPIO_P22,				/**< GPIO port P22 */
	E_DD_PMC_GPIO_P23,				/**< GPIO port P23 */
	E_DD_PMC_GPIO_P24,				/**< GPIO port P24 */
	E_DD_PMC_GPIO_P25,				/**< GPIO port P25 */
	E_DD_PMC_GPIO_P26,				/**< GPIO port P26 */
	E_DD_PMC_GPIO_P27,				/**< GPIO port P27 */
	E_DD_PMC_GPIO_P30,				/**< GPIO port P30 */
	E_DD_PMC_GPIO_P31,				/**< GPIO port P31 */
	E_DD_PMC_GPIO_P32,				/**< GPIO port P32 */
	E_DD_PMC_GPIO_P33,				/**< GPIO port P33 */
	E_DD_PMC_GPIO_P34,				/**< GPIO port P34 */
	E_DD_PMC_GPIO_P35,				/**< GPIO port P35 */
	E_DD_PMC_GPIO_P36,				/**< GPIO port P36 */
	E_DD_PMC_GPIO_P37,				/**< GPIO port P37 */
	E_DD_PMC_GPIO_P44,				/**< GPIO port P44 */
	E_DD_PMC_GPIO_P45,				/**< GPIO port P45 */
	E_DD_PMC_GPIO_P46,				/**< GPIO port P46 */
	E_DD_PMC_GPIO_PORT_MAX			/**< GPIO port maximum value */
} E_DD_PMC_GPIO_PORT;


/*----------------------------------------------------------------------*/
/* Structure															*/
/*----------------------------------------------------------------------*/
/* Nothing Special */

/*----------------------------------------------------------------------*/
/* Global Data															*/
/*----------------------------------------------------------------------*/
/* Nothing Special */

/*----------------------------------------------------------------------*/
/* Macro																*/
/*----------------------------------------------------------------------*/
/* Nothing Special */

/* @} */	// dd_pmc_gpio_definition group

/** @weakgroup dd_pmc_gpio_api
@{*/
/*----------------------------------------------------------------------*/
/* Function																*/
/*----------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif

/**
Set the functionality of a selectable GPIO port.<br>
It is set to the EPCR(External Port Control Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [in]  function	Function type.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_FUNC_GPIO
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_FUNC_HWMODE
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Input parameter error.
*/
INT32 Dd_PMC_GPIO_Set_Gpio_Function( E_DD_PMC_GPIO_PORT port, UCHAR function );

/**
Get the functionality of a selectable GPIO port.<br>
It is get from the EPCR(External Port Control Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [out] function	Function type.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_FUNC_GPIO
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_FUNC_HWMODE
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Input parameter error.
*/
INT32 Dd_PMC_GPIO_Get_Gpio_Function( E_DD_PMC_GPIO_PORT port, UCHAR* function );

/**
Set the direction of a selectable GPIO port.<br>
It is set to the DDR(Data Direction Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [in]  direction	Direction type.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_DIR_IN
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_DIR_OUT
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Error occurred.
*/
INT32 Dd_PMC_GPIO_Set_Gpio_Direction( E_DD_PMC_GPIO_PORT port, UCHAR direction );

/**
Get the direction of a selectable GPIO port.<br>
It is get from the DDR(Data Direction Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [out] direction	Direction type.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_DIR_IN
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_DIR_OUT
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Error occurred.
*/
INT32 Dd_PMC_GPIO_Get_Gpio_Direction( E_DD_PMC_GPIO_PORT port, UCHAR* direction );

/**
Set the state of a selectable GPIO port.<br>
It is set to the PDR(Port Data Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [in]  status		Port status.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_STATUS_LOW
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_STATUS_HIGH
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Error occurred.
*/
INT32 Dd_PMC_GPIO_Set_Gpio_Status( E_DD_PMC_GPIO_PORT port, UCHAR status );

/**
Get the state of a selectable GPIO port.<br>
It is get from the PDR(Port Data Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [out] status		Port status.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_STATUS_LOW
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_STATUS_HIGH
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Error occurred.
*/
INT32 Dd_PMC_GPIO_Get_Gpio_Status( E_DD_PMC_GPIO_PORT port, UCHAR* status );

/**
Set the Pull-up/down enable state of a selectable GPIO port.<br>
It is set to the PUDER(Pull-up/down Enable Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [in]  enable		Pull-up/down enable state.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_PUD_OFF
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_PUD_ON
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Error occurred.
*/
INT32 Dd_PMC_GPIO_Set_Gpio_Pull_Up_Down_Enable( E_DD_PMC_GPIO_PORT port, UCHAR enable );

/**
Get the Pull-up/down enable state of a selectable GPIO port.<br>
It is get from the PUDER(Pull-up/down Enable Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [out] enable		Pull-up/down enable state.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_PUD_OFF
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_PUD_ON
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Error occurred.
*/
INT32 Dd_PMC_GPIO_Get_Gpio_Pull_Up_Down_Enable( E_DD_PMC_GPIO_PORT port, UCHAR* enable );

/**
Set the Pull-up/down state of a selectable GPIO port.<br>
It is set to the PUDCR(Pull-up/down Control Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [in]  control	Pull-up/down state.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_PUD_DOWN
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_PUD_UP
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Error occurred.
*/
INT32 Dd_PMC_GPIO_Set_Gpio_Pull_Up_Down_Ctrl( E_DD_PMC_GPIO_PORT port, UCHAR control );

/**
Get the Pull-up/down state of a selectable GPIO port.<br>
It is get from the PUDCR(Pull-up/down Control Register) value.
@param [in]  port		Port name. See @ref E_DD_PMC_GPIO_PORT
@param [out] control	Pull-up/down state.
						  <ul>
							  <li>0:@ref D_DD_PMC_GPIO_GPIO_PUD_DOWN
							  <li>1:@ref D_DD_PMC_GPIO_GPIO_PUD_UP
						  </ul>
@retval D_DDIM_OK					Success.
@retval D_DD_PMC_GPIO_INPUT_PARAM_ERROR	Error occurred.
*/
INT32 Dd_PMC_GPIO_Get_Gpio_Pull_Up_Down_Ctrl( E_DD_PMC_GPIO_PORT port, UCHAR* control );

#ifdef __cplusplus
}
#endif

/* @} */	// dd_pmc_gpio_api group

#endif	// _DD_PMC_GPIO_H_
